package com.woniuxy.mqconsumer.service;

import com.woniuxy.mqconsumer.entity.Book;
import com.woniuxy.mqconsumer.mapper.BookMapper;
import com.woniuxy.mqconsumer.mapper.OrderMapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    OrderMapper orderMapper ;

    @Autowired
    BookMapper bookMapper ;
    @Transactional
    public boolean cancelOrder(String orderNum, List<Book> lists) {
        long l = orderMapper.selectOrderCountByOrderNum(orderNum);
        if (l > 0 ){
            orderMapper.updateOrderStateByOrderNum(orderNum);
            for (Book book :lists) {
                bookMapper.updateBookStoreCountById(book.getId(),book.getBuyCount());
            }
        }
        return true ;
    }
}
